package com.shan.thread;

/**
 * description
 * 线程优先级
 *
 * @author shanzheng <br/>
 * @date 15:03 2019/1/16.<br/>
 * Modified By <br/>
 */
public class PriorityThreadDemo {
    public static void main(String[] args) {
        PriorityThread priorityThread1 = new PriorityThread();
        PriorityThread priorityThread2 = new PriorityThread();
        PriorityThread priorityThread3 = new PriorityThread();
        Thread thread1 = new Thread(priorityThread1, "线程A");
        Thread thread2 = new Thread(priorityThread2, "线程B");
        Thread thread3 = new Thread(priorityThread3, "线程C");
        thread1.setPriority(Thread.MAX_PRIORITY);
        thread2.setPriority(Thread.NORM_PRIORITY);
        thread3.setPriority(Thread.MIN_PRIORITY);

        thread1.start();
        thread2.start();
        thread3.start();
    }
}

class PriorityThread implements Runnable {

    @Override
    public void run() {
        for (int i = 0; i < 5; i++) {
            try {
                Thread.sleep(500);
            } catch (Exception e) {
                e.printStackTrace();
            }
            System.out.println(Thread.currentThread().getName()
                    + "运行，i = " + i);
        }
    }
}
